<template>
  <el-row :gutter="20">

    <el-col :xs="24" :sm="12">
      <el-tabs v-model="activeName" @tab-click="handleClick" type="border-card">
        <el-tab-pane label="基础配置" name="first">

          <el-form label-position="right" label-width="30%" :model="baseConfigData" size="mini">
            <el-form-item label="导入用户信息模板存储路径">
              <el-input v-model="baseConfigData.userImportTemplatePath" ></el-input>
            </el-form-item>
            <el-form-item label="导入组织信息模板存储路径">
              <el-input v-model="baseConfigData.organizationImportTemplatePath" ></el-input>
            </el-form-item>
            <el-form-item label="用户默认头像">
              <el-input v-model="baseConfigData.userDefaultAvatar" ></el-input>
            </el-form-item>
            <el-form-item label="用户默认背景图">
              <el-input v-model="baseConfigData.userDefaultHomepage" ></el-input>
            </el-form-item>
            <el-form-item label="文章默认封面图">
              <el-input v-model="baseConfigData.articleDefaultCover" ></el-input>
            </el-form-item>
            <el-form-item label="单个用户每天上传文件次数">
              <el-input-number v-model="baseConfigData.uploadDayTimes" :min="1"></el-input-number>
            </el-form-item>
            <el-form-item label="单个用户每天下载文件次数">
              <el-input-number v-model="baseConfigData.downloadDayTimes" :min="1"></el-input-number>
            </el-form-item>
            <el-form-item label="单个组织最大容纳人数">
              <el-input-number v-model="baseConfigData.organizationMaxCapacity" :min="1" :step="10"></el-input-number>
            </el-form-item>
            <el-form-item label="单个用户允许加入的组织数">
              <el-input-number v-model="baseConfigData.userJoinOrganizationMaxNum" :min="1"></el-input-number>
            </el-form-item>
            <el-form-item label="用户每月允许修改密码的次数">
              <el-input-number v-model="baseConfigData.userMonthUpdatePwdTimes" :min="1" :max="5"></el-input-number>
            </el-form-item>
            <el-form-item label="是否开启短信功能" >
              <el-radio-group v-model="baseConfigData.openSms">
                <el-radio :label="1" border>是</el-radio>
                <el-radio :label="0" border>否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="是否开启邮件功能" >
              <el-radio-group v-model="baseConfigData.openMsm">
                <el-radio :label="1" border>是</el-radio>
                <el-radio :label="0" border>否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="是否开启上传文件功能" >
              <el-radio-group v-model="baseConfigData.openUpload">
                <el-radio :label="1" border>是</el-radio>
                <el-radio :label="0" border>否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="是否开启下载文件功能" >
              <el-radio-group v-model="baseConfigData.openDownload">
                <el-radio :label="1" border>是</el-radio>
                <el-radio :label="0" border>否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="是否开启文本审核功能" >
              <el-radio-group v-model="baseConfigData.openTextValid">
                <el-radio :label="1" border>是</el-radio>
                <el-radio :label="0" border>否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="是否开启图片审核功能" >
              <el-radio-group v-model="baseConfigData.openImgValid">
                <el-radio :label="1" border>是</el-radio>
                <el-radio :label="0" border>否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="发布文章是否需要审批" >
              <el-radio-group v-model="baseConfigData.articleApproveRequire">
                <el-radio :label="1" border>是</el-radio>
                <el-radio :label="0" border>否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="文章审批后是否需要邮件通知" >
              <el-radio-group v-model="baseConfigData.approveArticleOpenEmailNotify">
                <el-radio :label="1" border>是</el-radio>
                <el-radio :label="0" border>否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="组织审批后是否需要邮件通知" >
              <el-radio-group v-model="baseConfigData.approveOrganizationOpenEmailNotify">
                <el-radio :label="1" border>是</el-radio>
                <el-radio :label="0" border>否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="用户审批后是否需要邮件通知" >
              <el-radio-group v-model="baseConfigData.approveUserOpenEmailNotify">
                <el-radio :label="1" border>是</el-radio>
                <el-radio :label="0" border>否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="用户初始密码">
              <el-input v-model="baseConfigData.initPassword" ></el-input>
            </el-form-item>
            <el-form-item label="AES前后端加解密KEY">
              <el-input v-model="baseConfigData.aesKey" ></el-input>
            </el-form-item>
            <el-form-item label="AES前后端加解密IV">
              <el-input v-model="baseConfigData.aesIv" ></el-input>
            </el-form-item>
            <el-form-item align="left" >
              <el-button type="primary"
                         :disabled=" userRole !== 'SUPER_ADMIN' "
                         @click="submitBachConfig" :loading="baseConfigLoading">保存</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="网站配置" name="second">
          <el-form label-position="right" label-width="20%" :model="webInfoConfig" size="mini">
            <el-form-item label="网站名称">
              <el-input v-model="webInfoConfig.webName" ></el-input>
            </el-form-item>
            <el-form-item label="网站标题">
              <el-input v-model="webInfoConfig.webTitle" ></el-input>
            </el-form-item>
            <el-form-item label="备案时间范围">
              <el-input v-model="webInfoConfig.timeScope" placeholder="2024~2025"></el-input>
            </el-form-item>
            <el-form-item label="备案号">
              <el-input v-model="webInfoConfig.beianNumber" ></el-input>
            </el-form-item>
            <el-form-item label="备案人">
              <el-input v-model="webInfoConfig.beianUser" ></el-input>
            </el-form-item>
            <el-form-item label="网站背景图">
              <el-input v-model="webInfoConfig.backgroundImage" placeholder="请填写图片访问链接"></el-input>
              <el-upload
                class="upload-demo"
                action=""
                :http-request="uploadImage"
                :show-file-list="false">
                <el-button size="small" type="primary" plain :disabled=" userRole !== 'SUPER_ADMIN' ">点击上传</el-button>
              </el-upload>
            </el-form-item>
            <el-form-item align="left" >
              <el-button type="primary" :disabled=" userRole !== 'SUPER_ADMIN' "
                         @click="submitWebConfig"
                         :loading="webInfoConfigLoading">保存</el-button>
            </el-form-item>
          </el-form>

        </el-tab-pane>
        <el-button v-if="showButton" plain size="small" type="primary" icon="el-icon-plus" @click="addNotice()" style="margin-bottom: 20px;">添加</el-button>
        <el-tab-pane label="公告信息" name="three">
          <el-table :data="noticeList" style="width: 100%" stripe>
            <el-table-column align="center" label="序号" width="50" type="index"></el-table-column>
            <el-table-column prop="noticeTitle" label="标题" width="100"></el-table-column>
            <el-table-column prop="noticeVersion" label="版本号" width="100"></el-table-column>
            <el-table-column prop="noticeType" label="类型" width="80" align="center">
              <template slot-scope="scope">
                <el-tag v-if="scope.row.noticeType === 1" type="primary">系统公告</el-tag>
                <el-tag v-if="scope.row.noticeType === 2" type="info">组织公告</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="noticeStatus" label="公告状态" width="150" align="center">
              <template slot-scope="scope">
                <el-tag v-if="scope.row.noticeStatus === 1" type="danger">待发布</el-tag>
                <el-tag v-if="scope.row.noticeStatus === 2" type="success">已发布</el-tag>
              </template>
            </el-table-column>
            <el-table-column  align="center" label="操作">
              <template slot-scope="scope">
                <el-button icon="el-icon-search" plain type="primary" size="mini" @click="fetchNoticeDetail(scope.row.id)">查看</el-button>
                <el-button :disabled=" userRole !== 'SUPER_ADMIN' "
                           icon="el-icon-edit" plain type="info" size="mini"
                           @click="editNoticeInfo(scope.row.id)">编辑</el-button>
                <el-button :disabled=" userRole !== 'SUPER_ADMIN' "
                           icon="el-icon-edit-outline" plain type="success" size="mini"
                           @click="delNotice(scope.row.id)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>

        </el-tab-pane>

        <div style="margin-top: 10px;" v-if="showButton">
          <el-pagination background
                         @size-change="handleSizeChange"
                         @current-change="handleCurrentChange"
                         :current-page="param.pageNo"
                         :page-sizes="[10, 20, 50]"
                         :page-size="param.pageSize"
                         layout="total, sizes, prev, pager, next, jumper"
                         :total="param.total">
          </el-pagination>
        </div>

        <el-divider content-position="center" v-if="showDivider">OSS基础配置</el-divider>
        <el-tab-pane label="OSS配置" name="four">
          <el-form label-position="right" label-width="20%" :model="ossData" size="mini">
            <el-form-item label="域名">
              <el-input v-model="ossData.endPoint" disabled></el-input>
            </el-form-item>
            <el-form-item label="桶域名">
              <el-input v-model="ossData.bucketDomain" disabled></el-input>
            </el-form-item>
            <el-form-item label="桶名">
              <el-input v-model="ossData.bucketName" disabled></el-input>
            </el-form-item>
          </el-form>
          <el-divider content-position="center" v-if="showDivider">OSS扩展配置</el-divider>
          <el-form label-position="right" label-width="25%" :model="ossExtendData" size="mini">
            <el-form-item label="文章中图片存储目录">
              <el-input v-model="ossExtendData.articleImgStorageDirectory" ></el-input>
            </el-form-item>
            <el-form-item label="文件存储目录">
              <el-input v-model="ossExtendData.fileStorageDirectory" ></el-input>
            </el-form-item>
            <el-form-item label="用户头像存储目录">
              <el-input v-model="ossExtendData.userAvatarStorageDirectory" ></el-input>
            </el-form-item>
            <el-form-item label="组织头像存储目录">
              <el-input v-model="ossExtendData.organizationAvatarStorageDirectory" ></el-input>
            </el-form-item>
            <el-form-item label="用户主页背景图存储目录">
              <el-input v-model="ossExtendData.userHomepageStorageDirectory" ></el-input>
            </el-form-item>
            <el-form-item label="分类背景图存储目录">
              <el-input v-model="ossExtendData.categoryCoverStorageDirectory" ></el-input>
            </el-form-item>
            <el-form-item label="网站背景图存储目录">
              <el-input v-model="ossExtendData.websiteCoverDirectory" ></el-input>
            </el-form-item>
            <el-form-item align="left" >
              <el-button type="primary" :disabled=" userRole !== 'SUPER_ADMIN' "
                         @click="saveOssExtendConfig"
                         :loading="saveOssExtendConfigLoading">保存</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>

      </el-tabs>
    </el-col>

    <el-col :xs="24" :sm="12">
      <el-tabs v-model="active" @tab-click="handleClick" type="border-card" >
        <el-tab-pane label="图片校验规则配置" name="four">

          <el-form label-position="top" label-width="60%" :model="baseConfigData">
            <el-form-item label="名称" >
              <el-input v-model="baseConfigData.name"></el-input>
            </el-form-item>
            <el-form-item label="活动区域">
              <el-input v-model="baseConfigData.name1"></el-input>
            </el-form-item>
            <el-form-item label="活动形式">
              <el-input v-model="baseConfigData.name2"></el-input>
            </el-form-item>
          </el-form>


        </el-tab-pane>
        <el-tab-pane label="文本校验规则配置" name="five"></el-tab-pane>
      </el-tabs>
    </el-col>

    <el-drawer :title="title" :visible.sync="drawer" direction="rtl" :before-close="handleClose" :wrapper-closable="false">
      <el-form :model="noticeDetailData" ref="noticeDetailData" label-width="120px" label-position="right" style="margin-right: 20px;">
        <el-form-item label="标题：" prop="noticeTitle">
          <el-input v-model="noticeDetailData.noticeTitle" disabled/>
        </el-form-item>
        <el-form-item label="版本号：" prop="noticeVersion">
          <el-input v-model="noticeDetailData.noticeVersion" placeholder="请输入公告版本号" disabled/>
        </el-form-item>
        <el-form-item label="创建人：" prop="createrName">
          <el-input v-model="noticeDetailData.createrName" disabled />
        </el-form-item>
        <el-form-item label="公告类型：" prop="noticeType">
          <el-radio-group v-model="noticeDetailData.noticeType" disabled>
            <el-radio :label = 1 border>系统公告</el-radio>
            <el-radio :label = 2 border>组织公告</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="组织：" prop="organizationId" v-if="noticeDetailData.noticeType === 2">
          <el-select v-model="noticeDetailData.organizationId" clearable filterable style="width:400px;" disabled >
            <el-option v-for="item in options" :key="item.organizationId" :label="item.organizationName" :value="item.organizationId"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="公告状态：" prop="noticeStatus">
          <el-radio-group v-model="noticeDetailData.noticeStatus">
            <el-radio :label = 1 border>待发布</el-radio>
            <el-radio :label = 2 border>已发布</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="内容：" prop="noticeContent">
          <el-input v-model="noticeDetailData.noticeContent" type="textarea"/>
        </el-form-item>
        <el-form-item label="创建时间：" prop="createTime">
          <el-input v-model="noticeDetailData.createTime" disabled/>
        </el-form-item>
      </el-form>
      <el-row style="margin-left: 40px">
        <el-button size="small" type="danger" plain @click="handleClose" v-if="title === '编辑公告'">取消</el-button>
        <el-button size="small" type="success" plain @click="submitEdit" v-if="title === '编辑公告'">提交</el-button>
        <el-button size="small" type="success" plain @click="handleClose" v-if="title === '公告详情'">关闭</el-button>
      </el-row>
    </el-drawer>

    <el-drawer title="添加公告" :visible.sync="addDrawer" direction="rtl" :before-close="handleAddClose" :wrapper-closable="false">
      <el-form :model="noticeAddData" ref="noticeDetailData" label-width="120px" label-position="right" style="margin-right: 20px;">
        <el-form-item label="标题：" prop="noticeTitle">
          <el-input v-model="noticeAddData.noticeTitle" placeholder="请输入公告标题" show-word-limit maxlength="10" clearable/>
        </el-form-item>
        <el-form-item label="版本号：" prop="noticeVersion">
          <el-input v-model="noticeAddData.noticeVersion" placeholder="请输入公告版本号" show-word-limit maxlength="10" clearable/>
        </el-form-item>
        <el-form-item label="公告类型：" prop="noticeType">
          <el-radio-group v-model="noticeAddData.noticeType" >
            <el-radio :label = 1 border >系统公告</el-radio>
            <el-radio :label = 2 border>组织公告</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="组织：" prop="organization" v-if="noticeAddData.noticeType === 2">
          <el-select
            v-model="value"
            filterable
            remote
            reserve-keyword
            placeholder="请输入关键词"
            :remote-method="remoteMethod"
            :loading="loading">
            <el-option
              v-for="item in options"
              :key="item.organizationId"
              :label="item.organizationName"
              :value="item.organizationId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="内容：" prop="noticeContent">
          <el-input v-model="noticeAddData.noticeContent" type="textarea" placeholder="请输入公告内容" show-word-limit maxlength="50" clearable/>
        </el-form-item>
      </el-form>
      <el-row style="margin-left: 40px">
        <el-button size="small" type="danger" plain @click="handleAddClose" >取消</el-button>
        <el-button size="small" type="success" plain @click="submitAdd">提交</el-button>
      </el-row>
    </el-drawer>

  </el-row>



</template>

<script>
import { getBaseSystemConfig,
  saveBaseSystemConfig,
  getWebInfo,
  saveWebInfo,
  allNotice,
  noticeDetail,
  editNotice,
  delNotice,
  createNotice,
  getOssBaseConfig,
  saveOssBaseConfig,
  getOssExtendConfig,
  saveOssExtendConfig } from "@/api/system.js"
import { uploadFile } from "@/api/file";
import { dateFormat } from '@/utils/date';
import {WEBSITE_COVER} from "@/utils/fileType";
import { organizationListByKeyword } from "@/api/organization";
import { getUserRole } from "@/utils/userToken";

export default {
  data() {
    return {
      activeName: 'first',
      active: "three",
      baseConfigData: {
        userImportTemplatePath: "",
        organizationImportTemplatePath: "",
        uploadDayTimes: 1,
        userDefaultHomepage: "",
        downloadDayTimes: 1,
        openSms: "",
        openMsm: "",
        openUpload: "",
        openDownload: "",
        openTextValid: "",
        openImgValid: "",
        initPassword: "",
        aesKey: "",
        aesIv: "",
        organizationMaxCapacity: 50,
        userJoinOrganizationMaxNum: 1,
        userMonthUpdatePwdTimes: 1,
        userDefaultAvatar: "",
        articleApproveRequire: "",
        approveArticleOpenEmailNotify: "",
        approveOrganizationOpenEmailNotify: "",
        approveRoleOpenEmailNotify: "",
        approveUserOpenEmailNotify: "",
        articleDefaultCover: ''
      },
      webInfoConfig: {
        webName: "",
        webTitle: "",
        backgroundImage: "",
        timeScope: "",
        beianNumber: "",
        beianUser: ""
      },
      baseConfigLoading: false,
      webInfoConfigLoading: false,
      noticeList: [],
      param: {
        pageNo: 1,
        pageSize: 10,
        total: 0
      },
      current: 1,
      noticeDetailData: {},
      noticeAddData: {},
      drawer: false,
      addDrawer: false,
      title: "公告详情",
      showButton: false,
      showDivider: false,
      ossData: {
        endPoint: "",
        bucketDomain: "",
        bucketName: "",
        accessKeyId: "",
        accessKeySecret: "",
        imgSize: "",
        fileSize: "",
        imgType: ""
      },
      ossExtendData: {
        articleImgStorageDirectory: "",
        fileStorageDirectory: "",
        userAvatarStorageDirectory: "",
        organizationAvatarStorageDirectory: "",
        userHomepageStorageDirectory: "",
        categoryCoverStorageDirectory: "",
        websiteCoverDirectory: ""
      },
      saveOssBaseConfigLoading: false,
      saveOssExtendConfigLoading: false,
      options: [
        {
          value: 1,
          label: "11"
        },
        {
          value: 2,
          label: "22"
        }
      ],
      value: [1],
      list: [],
      loading: false,
      userRole: ''
    };
  },

  created() {
    this.getBaseSystemConfig();
    this.userRole = getUserRole();
  },

  methods: {
    submitWebConfig() {
      this.webInfoConfigLoading = true;
      saveWebInfo(this.webInfoConfig).then(res => {
        if (res.code === 200) {
          this.$notify({
            title: '成功',
            message: '保存成功',
            type: 'success',
            duration: 1500
          });
          this.webInfoConfigLoading = false;
          this.getWebInfo();
        } else {
          this.$notify.error({
            title: '错误',
            message: res.message,
            duration: 1500
          });
          this.webInfoConfigLoading = false;
        }
      })
    },

    // 保存OSS基础配置信息
    saveOssBaseConfig() {
      this.saveOssBaseConfigLoading = true;
      this.ossData.accessKeySecret = '';
      this.ossData.accessKeyId = '';
      saveOssBaseConfig(this.ossData).then(res => {
        if (res.code === 200) {
          this.$notify({
            title: '成功',
            message: '保存成功',
            type: 'success',
            duration: 1500
          });
          this.fetchOssConfig();
          this.saveOssBaseConfigLoading = false;
        } else {
          this.$notify.error({
            title: '错误',
            message: res.message,
            duration: 1500
          });
          this.saveOssBaseConfigLoading = false;
        }
      })
    },

    // 保存OSS扩展配置信息
    saveOssExtendConfig() {
      this.saveOssExtendConfigLoading = true;
      saveOssExtendConfig(this.ossExtendData).then(res => {
        if (res.code === 200) {
          this.$notify({
            title: '成功',
            message: '保存成功',
            type: 'success',
            duration: 1500
          });
          this.fetchOssExtendConfig();
          this.saveOssExtendConfigLoading = false;
        } else {
          this.$notify.error({
            title: '错误',
            message: res.message,
            duration: 1500
          });
          this.saveOssExtendConfigLoading = false;
        }
      })
    },

    // 获取系统基础配置信息
    getBaseSystemConfig() {
      getBaseSystemConfig().then(res => {
        if (res.code === 200) {
          this.baseConfigData = res.data;
        } else {
          this.$notify.error({
            title: '错误',
            message: res.message,
            duration: 1500
          });
        }
      })
    },

    fetchNoticeDetail(id) {
      noticeDetail(id).then(res => {
        if (res.code === 200) {
          this.drawer = true;
          this.noticeDetailData = res.data
        }
      })

      this.getOrganizationListByKeyword()
    },

    addNotice() {
      this.addDrawer = true;
      this.getOrganizationListByKeyword();
    },

    // 根据关键字查询组织列表
    getOrganizationListByKeyword(keyword) {
      organizationListByKeyword(keyword).then(res => {
        if (res.code === 200) {
          this.options = res.data;
        }
      })
    },

    submitAdd() {
      if (this.noticeAddData.noticeType === 1) {
        this.noticeAddData.organizationId = '';
      } else {
        this.noticeAddData.organizationId = this.value;
      }
      createNotice(this.noticeAddData).then(res => {
        if (res.code === 200) {
          this.$notify({
            title: '成功',
            message: '添加成功',
            type: 'success',
            duration: 1500
          });
          this.handleAddClose();
        } else {
          this.$notify.error({
            title: '错误',
            message: res.message,
            duration: 1500
          });
        }
      })
    },

    editNoticeInfo(id) {
      noticeDetail(id).then(res => {
        if (res.code === 200) {
          this.drawer = true;
          this.title = '编辑公告';
          this.noticeDetailData = res.data
        }
      })
      this.getOrganizationListByKeyword()
    },

    delNotice(id) {
      this.$confirm('确认删除这条记录吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 发送删除请求
        delNotice(id).then(response => {
          if (response.code === 200) {
            this.$notify({
              title: '成功',
              message: '删除成功',
              type: 'success',
              duration: 1500
            });
          } else {
            this.$notify.error({
              title: '错误',
              message: response.message,
              duration: 1500
            });
          }
          // 刷新列表
          this.fetchNoticeList();
        })
      }).catch(() => {
        // 取消删除
      });
    },

    submitEdit() {
      editNotice(this.noticeDetailData).then(res => {
        if (res.code === 200) {
          this.$notify({
            title: '成功',
            message: '编辑成功',
            type: 'success',
            duration: 1500
          });
          this.handleClose();
        } else {
          this.$notify.error({
            title: '错误',
            message: res.message,
            duration: 1500
          });
        }
      })
    },

    getWebInfo() {
      getWebInfo().then(res => {
        if (res.code === 200) {
          this.webInfoConfig = res.data;
        } else {
          this.$notify.error({
            title: '错误',
            message: res.message,
            duration: 1500
          });
        }
      })
    },

    // 上传图片
    uploadImage(file) {
      const data = new FormData();
      data.append('file', file.file);
      data.append('type', WEBSITE_COVER);
      uploadFile(data).then(response => {
        if(response.code === 200){
          this.webInfoConfig.backgroundImage = response.data;
        } else {
          this.$notify.error({
            title: '错误',
            message: response.message,
            duration: 1500
          });
        }
      }).catch(err => {
        this.$message({
          type: 'error',
          message: '上传失败'
        })
      })
    },

    // 保存基础配置
    submitBachConfig() {
      this.baseConfigLoading = true;
      saveBaseSystemConfig(this.baseConfigData).then(res => {
        if (res.code === 200) {
          this.$notify({
            title: '成功',
            message: '保存成功',
            type: 'success',
            duration: 1500
          });
          this.getBaseSystemConfig();
          this.baseConfigLoading = false;
        } else {
          this.$notify.error({
            title: '错误',
            message: res.message,
            duration: 1500
          });
          this.baseConfigLoading = false;
        }
      })
    },

    fetchNoticeList() {
      allNotice(this.param).then(res => {
        if (res.code === 200) {
          this.noticeList = res.data.list;
          this.param.total = res.data.total;
        }
      })
    },

    // 获取OSS配置信息
    fetchOssConfig() {
      getOssBaseConfig().then(res => {
        if (res.code === 200) {
          this.ossData = res.data;
        }
      })
    },

    handleClick(tab, event) {
      this.showButton = false;
      this.showDivider = false;
      if (tab.label === "基础配置") {
        this.getBaseSystemConfig();
      } else if (tab.label === "网站配置") {
        this.getWebInfo();
      } else if (tab.label === "公告信息") {
        this.showButton = true;
        this.fetchNoticeList();
      } else if (tab.label === 'OSS配置') {
        this.showDivider = true;
        this.fetchOssConfig();
        this.fetchOssExtendConfig();
      }
    },

    // 获取OSS扩展配置信息
    fetchOssExtendConfig() {
      getOssExtendConfig().then(res => {
        if (res.code === 200) {
          this.ossExtendData = res.data;
        }
      })
    },

    // 格式化日期
    getFormat(date){
      return dateFormat(date);
    },

    handleClose() {
      this.drawer = false;
      this.title = '公告详情';
      this.noticeDetailData = {};
      this.fetchNoticeList();
    },

    handleAddClose() {
      this.addDrawer = false;
      this.noticeAddData = {};
      this.fetchNoticeList();
    },

    // val 是切换之后的每页显示多少条
    handleSizeChange(val) {
      this.param.pageSize = val;
      this.fetchNoticeList();
    },

    // 当页码改变后触发此方法 val是当前点击（或输入）的页码
    handleCurrentChange(val) {
      this.param.pageNo = val;
      this.fetchNoticeList();
    },

    remoteMethod(query) {
      if (query !== '') {
        this.loading = true;
        setTimeout(() => {
          this.loading = false;
          /*this.options = this.list.filter(item => {
            return item.label.toLowerCase()
              .indexOf(query.toLowerCase()) > -1;
          });*/
          this.getOrganizationListByKeyword(query);
        }, 200);
      } else {
        this.getOrganizationListByKeyword();
      }
    }


  }
};
</script>

<style>
</style>
